package com.eva.androidlibrary.icon;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.TextView;

import com.eva.androidlibrary.utils.ResourceUtil;

/**
 * Class description
 *
 * @author GUXIA318
 * @date 2015-09-25 9:58
 */
public class IconTextView extends TextView {
    public IconTextView(Context context) {
        super(context);
        init();
    }

    public IconTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public IconTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public IconTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init() {
        int iconfontResId = ResourceUtil.getResourceId(getContext(), "R.raw.iconfont.ttf");
        if (iconfontResId <= 0) {
            throw new RuntimeException("no iconfont.ttf at res/raw folder");
        }

        Typeface typeFace = TypefaceManager.IconicTypeface.getInstance(iconfontResId).getTypeface(getContext());
        setTypeface(typeFace);
    }
}
